// pages/index/index.js
// const API = require('../../api/index');
Page({

  /**
   * 页面的初始数据
   */
  data: {
    currentTab: 0,
    items: [
      {
        "iconPath": "../../assets/tabBar/home.png",
        "selectedIconPath": "../../assets/tabBar/home_hover.png",
        "text": "首页"
      },
      {
        "iconPath": "../../assets/tabBar/location.png",
        "selectedIconPath": "../../assets/tabBar/location_hover.png",
        "text": "围栏"
      },
      {
        "iconPath": "../../assets/tabBar/dolist.png",
        "selectedIconPath": "../../assets/tabBar/dolist_hover.png",
        "text": "待办"
      },
      {
        "iconPath": "../../assets/tabBar/news.png",
        "selectedIconPath": "../../assets/tabBar/news_hover.png",
        "text": "消息"
      },
      {
        "iconPath": "../../assets/tabBar/me.png",
        "selectedIconPath": "../../assets/tabBar/me_hover.png",
        "text": "我的"
      }
    ],
    hotsongs: [],
  },

  swichNav: function (e) {
    let that = this;
    let temp = e.target.dataset.current
    let barTitle = '汕大精防'
    if (this.data.currentTab === temp) {
      return false;
    } else {
      barTitle = temp == 0 ? barTitle : (temp == 1 ? '电子围栏' : (temp == 2 ? '代办事项' : (temp == 3 ? '消息' : barTitle)))
      that.setData({
        currentTab: temp
      })
      wx.setNavigationBarTitle({
        title: barTitle,
        fail: (err) => { console.log('BarTitel设置失败err:', err)},
      });
        
    }
  },

  gethotsongs() {
    API.gethotsongs({
      type: 7,
    }).then(res => {
        console.log(res);
        // 大厂API接口的维定 code 0 没有问题
        if (res.code === 200) {  //严谨
          this.setData({
            hotsongs: res.data
          })
        }
      })

  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    // this.gethotsongs();
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})